package com.javaGather.day7;

public class Test {
    public static void main(String[] args) {

        /**
         * 可变参数
         */

        //arr[0] = 1,arr[1] = 1
        System.out.println(sum(1, 1,3));
        System.out.println(sum(2, 2, 2));

        System.out.println(sum1(2, 2, 2));
        System.out.println(sum1(2, 2, 2));
    }


    /**
     * int... ----底层基于数组实现
     *
     * @param a 数组
     * @return
     */
    public static int sum(int... a) {
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
//            System.out.println(a[i]);
            sum += a[i];

        }
        return sum;
    }

    public static int sum1(int c, int... a) {
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
//            System.out.println(a[i]);
            sum += a[i];

        }
        return sum + c;
    }
}
